<template>
  <div class="complaint-wall">
    <div class="wall-header">
      <div class="header-content">
        <h1>校园吐槽墙</h1>
        <p>分享你的想法，吐槽校园生活</p>
        <div class="decoration-icons">
          <span>📢</span>
          <span>💬</span>
          <span>📝</span>
        </div>
      </div>
    </div>
    
    <div class="wall-container">
      <!-- 左侧装饰 -->
      <div class="wall-decoration left">
        <div class="brick" v-for="n in 3" :key="'left-'+n"></div>
        <div class="graffiti">😊</div>
      </div>
      
      <!-- 主内容区 -->
      <div class="wall-content">
        <div class="wall-notice">
          <div class="notice-content">
            <i class="el-icon-info"></i>
            <span>文明吐槽，理性建议，共建美好校园~</span>
          </div>
          
        </div>
        
        <el-form :model="form" label-width="auto" class="complaint-form">
          <div class="post-it-note" :class="{ 'shake-animation': isShaking }">
            <el-form-item label="我想吐槽..." class="form-label">
              <el-input 
                v-model="form.info" 
                type="textarea" 
                placeholder="今天食堂的菜太咸了..."
                :autosize="{ minRows: 4, maxRows: 6 }"
                @focus="stopShaking"
                maxlength="200"
                show-word-limit
              />
            </el-form-item>
          </div>
          
          <div class="post-it-note yellow">
            <el-form-item label="如果能改进..." class="form-label">
              <el-input 
                v-model="form.reward" 
                type="textarea" 
                placeholder="希望食堂能少放点盐..."
                :autosize="{ minRows: 3, maxRows: 5 }"
                maxlength="100"
                show-word-limit
              />
            </el-form-item>
          </div>
          
          <div class="post-it-note pink">
            <el-form-item label="不然的话..." class="form-label">
              <el-input 
                v-model="form.punish" 
                type="textarea" 
                placeholder="我只能天天点外卖了..."
                :autosize="{ minRows: 3, maxRows: 5 }"
                maxlength="100"
                show-word-limit
              />
            </el-form-item>
          </div>
          
          <el-button 
            type="primary" 
            @click="onSubmit" 
            class="submit-btn"
            icon="el-icon-upload"
            :loading="isSubmitting"
          >
            贴到墙上
          </el-button>
        </el-form>
      </div>
      
      <!-- 右侧装饰 -->
      <div class="wall-decoration right">
        <div class="brick" v-for="n in 3" :key="'right-'+n"></div>
        <div class="graffiti">💪</div>
      </div>
    </div>
    
    <!-- 已有吐槽展示区 -->
    <div class="wall-posts" v-if="posts.length > 0">
      <div class="posts-header">
        <h2>大家的吐槽 <span class="posts-count">({{ posts.length }}条)</span></h2>
      </div>
      <div class="posts-container">
        <div 
          v-for="(post, index) in posts" 
          :key="index" 
          class="post"
          :class="getRandomPostItColor()"
          @mouseenter="hoveredPostIndex = index"
          @mouseleave="hoveredPostIndex = -1"
        >
          <p class="post-content">{{ post.info }}</p>
          <div class="post-footer">
            <span v-if="post.reward" class="improvement">建议: {{ post.reward }}</span>
            <span v-if="post.punish" class="consequence">否则: {{ post.punish }}</span>
          </div>
          <div class="post-date" v-if="hoveredPostIndex === index">
            {{ formatDate(new Date()) }}
          </div>
          <div class="post-actions">
<<<<<<< HEAD
            <span class="action-btn" :class="{ 'like-animate': likedIndex === index }" @click.stop="handleLike(index)">
              <i class="el-icon-thumb"></i>
              <span>{{ post.likeCount }}</span>
=======
            <span class="action-btn" @click.stop="handleLike(index)">
              <i class="el-icon-thumb"></i>
>>>>>>> 7b4717de243c0eb30f60ba38ada9f48f33056cd4
            </span>
            <span class="action-btn" @click.stop="handleShare(index)">
              <i class="el-icon-share"></i>
            </span>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 回到顶部 -->
    <el-backtop :right="50" :bottom="50" />
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'
import api from '../commonjs/api'

// 表单数据
const form = reactive({
  info: '',
  reward: '',
  punish: ''
})

// 模拟已有的吐槽帖子
const posts = ref([
<<<<<<< HEAD
  { info: '图书馆的空调开得太冷了，像冰窖一样', reward: '希望温度能调到26度左右', punish: '我只能穿羽绒服去学习了', likeCount: 0 },
  { info: '教学楼厕所的门锁坏了好几个', reward: '能不能定期检查维修一下', punish: '上厕所都没安全感了', likeCount: 0 },
  { info: '校园网在宿舍区信号太差', reward: '增加路由器', punish: '流量不够用', likeCount: 0 }
=======
  { info: '图书馆的空调开得太冷了，像冰窖一样', reward: '希望温度能调到26度左右', punish: '我只能穿羽绒服去学习了' },
  { info: '教学楼厕所的门锁坏了好几个', reward: '能不能定期检查维修一下', punish: '上厕所都没安全感了' },
  { info: '校园网在宿舍区信号太差了', reward: '增加几个路由器', punish: '流量都不够用了' }
>>>>>>> 7b4717de243c0eb30f60ba38ada9f48f33056cd4
])

// 新增状态
const isSubmitting = ref(false)
const isShaking = ref(false)
const hoveredPostIndex = ref(-1)
<<<<<<< HEAD
const likedIndex = ref(-1)
=======
>>>>>>> 7b4717de243c0eb30f60ba38ada9f48f33056cd4

// 提交吐槽
const onSubmit = () => {
  if (!form.info.trim()) {
    isShaking.value = true
    setTimeout(() => isShaking.value = false, 500)
    return
  }
  
  isSubmitting.value = true
  
  api.post('/api/selfimprovement', form).then((res) => {
    console.log(res)
    if (res.opResult === 0) {
      alert('吐槽已上墙！')
      posts.value.unshift({...form})
      form.info = ''
      form.reward = ''
      form.punish = ''
    } else {
      alert('提交失败，请稍后再试')
    }
  }).catch((err) => {
    console.error(err)
    alert('网络错误，吐槽没贴上去')
  }).finally(() => {
    isSubmitting.value = false
  })
}

// 随机便利贴颜色
const getRandomPostItColor = () => {
  const colors = ['yellow', 'pink', 'blue', 'green']
  return colors[Math.floor(Math.random() * colors.length)]
}

const stopShaking = () => {
  isShaking.value = false
}

const formatDate = (date) => {
  return `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}`
}

const handleLike = (index) => {
<<<<<<< HEAD
  posts.value[index].likeCount += 1
  likedIndex.value = index
  setTimeout(() => {
    likedIndex.value = -1
  }, 300)
  // 可选：调用后端接口同步点赞数
  // api.post('/api/selfimprovement/like', { id: posts.value[index].id })
=======
  alert('点赞功能前端演示')
>>>>>>> 7b4717de243c0eb30f60ba38ada9f48f33056cd4
}

const handleShare = (index) => {
  alert('分享功能前端演示')
}
</script>

<style scoped>
.complaint-wall {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
  font-family: 'Arial', sans-serif;
  position: relative;
}

.wall-header {
  text-align: center;
  margin-bottom: 30px;
  position: relative;
  background: linear-gradient(135deg, #f56c6c, #f78989);
  padding: 20px;
  border-radius: 10px;
  color: white;
  box-shadow: 0 4px 12px rgba(245, 108, 108, 0.2);
<<<<<<< HEAD
  /* 修改配色方案 */
  background: linear-gradient(135deg, #4CAF50, #8BC34A);
  /* 其他样式保持不变 */
=======
>>>>>>> 7b4717de243c0eb30f60ba38ada9f48f33056cd4
}

.header-content {
  position: relative;
  z-index: 1;
}
<<<<<<< HEAD
.wall-header {
  text-align: center;
  margin-bottom: 30px;
  background: linear-gradient(135deg, #4CAF50 0%, #8BC34A 100%);
  padding: 32px 20px 24px 20px;
  border-radius: 16px;
  color: #fff;
  box-shadow: 0 6px 24px rgba(76,175,80,0.15);
  position: relative;
}
.wall-header h1 {
  font-size: 2.8em;
  font-weight: bold;
  margin-bottom: 8px;
  letter-spacing: 2px;
  text-shadow: 1px 2px 8px rgba(0,0,0,0.08);
}

.wall-header p {
  font-size: 1.2em;
  opacity: 0.85;
  margin-bottom: 10px;
}

.decoration-icons {
  margin-top: 18px;
=======

.wall-header h1 {
  font-size: 2.5em;
  margin-bottom: 10px;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.2);
}

.wall-header p {
  font-size: 1.1em;
  opacity: 0.9;
}

.decoration-icons {
  margin-top: 15px;
>>>>>>> 7b4717de243c0eb30f60ba38ada9f48f33056cd4
}

.decoration-icons span {
  margin: 0 8px;
  font-size: 1.2em;
  opacity: 0.7;
}

.wall-container {
  display: flex;
  margin-bottom: 40px;
  position: relative;
}

.wall-decoration {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  width: 30px;
  position: relative;
}

.brick {
  height: 60px;
  background-color: #c4a484;
  border: 1px solid #8b5a2b;
  border-radius: 3px;
  margin: 5px 0;
  box-shadow: inset 0 0 5px rgba(0,0,0,0.1);
}

.graffiti {
  position: absolute;
  font-size: 20px;
  right: -15px;
  transform: rotate(15deg);
  opacity: 0.8;
}

.wall-content {
  flex: 1;
  padding: 0 20px;
}

.wall-notice {
  background: rgba(255,255,255,0.9);
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 20px;
  border-left: 4px solid #f56c6c;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.notice-content {
  display: flex;
  align-items: center;
  color: #666;
}

.notice-content i {
  margin-right: 8px;
  color: #f56c6c;
}

.complaint-form {
<<<<<<< HEAD
  background: #f5fbe6;
  padding: 28px 20px;
  border-radius: 14px;
  box-shadow: 0 2px 12px rgba(76,175,80,0.08);
}
/**/
.post-it-note {
  background: #fffde7;
  border-left: 6px solid #ffeb3b;
  border-radius: 8px;
  margin-bottom: 18px;
  box-shadow: 2px 2px 8px rgba(255,235,59,0.08);
}
.submit-btn {
  width: 100%;
  padding: 14px 0;
  font-size: 1.15em;
  background: linear-gradient(90deg, #43e97b 0%, #38f9d7 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  letter-spacing: 1px;
  box-shadow: 0 2px 8px rgba(56,249,215,0.12);
  transition: 0.2s, box-shadow 0.2s;
}
.submit-btn:hover {
  background: linear-gradient(90deg, #38f9d7 0%, #43e97b 100%);
  box-shadow: 0 4px 16px rgba(56,249,215,0.18);
}

/*
=======
  background-color: #f5f5f5;
  padding: 25px;
  border-radius: 10px;
  box-shadow: 0 0 15px rgba(0,0,0,0.08);
}

>>>>>>> 7b4717de243c0eb30f60ba38ada9f48f33056cd4
.post-it-note {
  background-color: #fff9c4;
  padding: 18px;
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: 3px 3px 8px rgba(0,0,0,0.1);
  border-left: 6px solid #ffeb3b;
  position: relative;
  transition: all 0.3s ease;
}
<<<<<<< HEAD
*/
=======

>>>>>>> 7b4717de243c0eb30f60ba38ada9f48f33056cd4
.post-it-note:hover {
  transform: translateY(-3px);
  box-shadow: 5px 5px 12px rgba(0,0,0,0.15);
}

.post-it-note.yellow {
  background-color: #fff9c4;
  border-left-color: #ffeb3b;
}

.post-it-note.pink {
  background-color: #ffcdd2;
  border-left-color: #f44336;
}

.post-it-note.blue {
  background-color: #bbdefb;
  border-left-color: #2196f3;
}

.post-it-note.green {
  background-color: #c8e6c9;
  border-left-color: #4caf50;
}

.form-label :deep(.el-form-item__label) {
  font-weight: bold;
  color: #555;
}

.submit-btn {
  width: 100%;
  padding: 14px;
  font-size: 1.1em;
  background-color: #f56c6c;
  border: none;
  transition: all 0.3s;
  letter-spacing: 1px;
  font-weight: bold;
}

.submit-btn:hover {
  background-color: #e64a4a;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(230, 74, 74, 0.3);
}
<<<<<<< HEAD
=======

.wall-posts {
  margin-top: 40px;
}

>>>>>>> 7b4717de243c0eb30f60ba38ada9f48f33056cd4
.posts-header {
  text-align: center;
  margin-bottom: 25px;
}

.posts-header h2 {
  color: #f56c6c;
  font-size: 1.8em;
  display: inline-block;
  position: relative;
}

.posts-header h2::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 3px;
  background: linear-gradient(90deg, #f56c6c, transparent);
  border-radius: 3px;
}

.posts-count {
  font-size: 0.8em;
  color: #999;
  margin-left: 8px;
}

.posts-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 25px;
}

.post {
  padding: 20px;
  border-radius: 8px;
  box-shadow: 3px 3px 8px rgba(0,0,0,0.1);
  transform: rotate(0.5deg);
  transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
  position: relative;
  overflow: hidden;
  cursor: default;
}

.post:hover {
  transform: rotate(0deg) scale(1.02);
  box-shadow: 5px 5px 15px rgba(0,0,0,0.15);
}

.post::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, rgba(255,255,255,0.3), transparent);
}

.post-content {
  font-weight: bold;
  margin-bottom: 12px;
  line-height: 1.5;
  position: relative;
  z-index: 1;
}

.post-footer {
  font-size: 0.9em;
  color: #555;
  position: relative;
  z-index: 1;
}

.improvement {
  display: block;
  margin-top: 10px;
  color: #4caf50;
  font-weight: 500;
}

.consequence {
  display: block;
  margin-top: 8px;
  color: #f44336;
  font-weight: 500;
}

.post-date {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 0.7em;
  color: #888;
  background: rgba(255,255,255,0.8);
  padding: 2px 6px;
  border-radius: 10px;
}

.post-actions {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
}

.action-btn {
<<<<<<< HEAD
  cursor: pointer;
  margin-right: 10px;
  color: #409EFF;
  display: inline-flex;
  align-items: center;
}

.action-btn i {
  margin-right: 4px;
=======
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  color: #666;
  font-size: 0.9em;
}

.action-btn:hover {
  background: #f56c6c;
  color: white;
  transform: scale(1.1);
>>>>>>> 7b4717de243c0eb30f60ba38ada9f48f33056cd4
}

.shake-animation {
  animation: shake 0.5s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

<<<<<<< HEAD
@keyframes likeScale {
  0% { transform: scale(1); }
  50% { transform: scale(1.4); }
  100% { transform: scale(1); }
}
.like-animate {
  animation: likeScale 0.3s;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .wall-container .posts-container {
    flex-direction: column !important;
    grid-template-columns: 1fr !important;
=======
/* 响应式设计 */
@media (max-width: 768px) {
  .wall-container {
    flex-direction: column;
>>>>>>> 7b4717de243c0eb30f60ba38ada9f48f33056cd4
  }
  
  .wall-decoration {
    flex-direction: row;
    width: 100%;
    margin: 10px 0;
    height: 30px;
  }
  
  .brick {
    width: 60px;
    height: 30px;
    margin: 0 5px;
  }
  
  .graffiti {
    top: -15px;
    right: auto;
    left: 50%;
    transform: rotate(15deg) translateX(-50%);
  }
  
  .wall-content {
    padding: 0;
  }
  
  .posts-container {
    grid-template-columns: 1fr;
  }
}
</style>